package com.xiaomi.web.interceptors;

import com.xiaomi.domain.UserEntity;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserEntity admin = (UserEntity) session.getAttribute("admin");
        if (admin != null){
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/admin/login.jsp");
        return false;
    }
}
